<?php

namespace App\Http\Requests\School;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

/**
 * Class StorePriceCategory
 * @package App\Http\Requests\School
 */
class StorePriceCategory extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' => [
                'required',
                'string',
                Rule::unique('price_categories')->where('school_id', \Auth::user()->school_id)
            ],
            'description' => 'string|nullable',
            'status' => 'required|integer'
        ];
    }

    /**
     * @return array
     */
    public function attributes()
    {
        return [
            'name' => '名称',
            'description' => '描述',
            'status' => '状态'
        ];
    }

    /**
     * @return array
     */
    public function messages()
    {
        return [
            'name.unique' => '已存在相同:attribute',
            'name.required' => '请填写:attribute',
            'name.string' => ':attribute数据类型错误',
            'description.string' => ':attribute数据类型错误',
            'status.required' => '请填写:attribute',
            'status.integer' => ':attribute数据类型错误'
        ];
    }
}
